# Maintainer: Peter Budai <peterbudai@hotmail.com>

_realname=yarn
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.17.3
pkgrel=1
pkgdesc="Fast, reliable, and secure dependency management (mingw-w64)"
arch=('any')
url="https://yarnpkg.com/"
license=("BSD")
depends=("${MINGW_PACKAGE_PREFIX}-nodejs")
source=("https://github.com/yarnpkg/${_realname}/releases/download/v${pkgver}/${_realname}-v${pkgver}.tar.gz")
sha256sums=('e3835194409f1b3afa1c62ca82f561f1c29d26580c9e220c36866317e043c6f3')

package() {
  cd "${srcdir}/${_realname}-v${pkgver}"

  install -dm755  "${pkgdir}"/${MINGW_PREFIX}/lib/node_modules/yarn
  cp -R * "${pkgdir}"/${MINGW_PREFIX}/lib/node_modules/yarn

  install -dm755 "${pkgdir}"/${MINGW_PREFIX}/bin
  cp bin/yarn "${pkgdir}"/${MINGW_PREFIX}/bin/
  cp bin/yarn.cmd "${pkgdir}"/${MINGW_PREFIX}/bin/
  cp bin/yarnpkg "${pkgdir}"/${MINGW_PREFIX}/bin/
  cp bin/yarnpkg.cmd "${pkgdir}"/${MINGW_PREFIX}/bin/

  # update path to point to the right place
  sed -i "s|$basedir/yarn.js|$basedir/../lib/node_modules/yarn/bin/yarn.js|" "${pkgdir}"/${MINGW_PREFIX}/bin/yarn
  sed -i 's|yarn.js|\\..\\lib\\node_modules\\yarn\\bin\\yarn.js|' "${pkgdir}"/${MINGW_PREFIX}/bin/yarn.cmd
  sed -i 's|./yarn.js|../lib/node_modules/yarn/bin/yarn.js|' "${pkgdir}"/${MINGW_PREFIX}/bin/yarnpkg

  install -Dm644 LICENSE "${pkgdir}/${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
  install -Dm644 README.md "${pkgdir}/${MINGW_PREFIX}/share/doc/${_realname}/README.md"
}
